#include "TargetBox.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "Elemental.h"

CTargetBox::CTargetBox(void)
{
	TypeofObj = Obj_TargetBox;
	RangeRect.top = 0;
	RangeRect.left = 0;
	RangeRect.right = 0;
	RangeRect.bottom = 0;
}


CTargetBox::~CTargetBox(void)
{
}

void CTargetBox::SetUpBox( int nX, int nY, short range)
{
	//Super hard coded because of no anchor points
	RangeRect.top = ((nY) - (range*16));
	RangeRect.left = ((nX) - (range*16));
	RangeRect.right = ((nY+32) + (range*16));
	RangeRect.bottom = ((nY+32) + (range*16));

}


void CTargetBox::Update( float fElapsedTime )
{

}
void CTargetBox::Render( void )
{

	RangeRect.top = (int)(GetPosY() - m_pRangedOwner->GetRange());
	RangeRect.left = (int)(GetPosX() -  m_pRangedOwner->GetRange());
	RangeRect.right = (int)(GetPosX() +  m_pRangedOwner->GetRange());
	RangeRect.bottom = (int)(GetPosY() +  m_pRangedOwner->GetRange());


	CSGD_Direct3D::GetInstance()->DrawRect( RangeRect, 255,0,0);
}
bool CTargetBox::CheckCollision( IEntity * pOther )
{
	if( CEntity::CheckCollision(pOther) != true )
	{
		return false;
	}
	switch( pOther->GetType() )
	{
		case Obj_Elemental:
			{
				if( m_pRangedOwner->GetTeam() != dynamic_cast<CElemental*>(pOther)->GetTeam() && dynamic_cast<CElemental*>(m_pRangedOwner)->GetLane() == dynamic_cast<CElemental*>(pOther)->GetLane())
				{
					dynamic_cast<CElemental*>(m_pRangedOwner)->SetTarget(dynamic_cast<CEntity*>(pOther));
					return true;
				}
			}
	}
}